package com.monitor.service.impl;

import com.monitor.common.aes.AESOperator;
import com.monitor.common.response.CodeMsg;
import com.monitor.common.response.ResponseFactory;
import com.monitor.common.response.Result;
import com.monitor.dao.SysUserDao;
import com.monitor.pojo.SysUser;
import com.monitor.service.LoginService;
import com.monitor.vo.LoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName LoginServiceImpl
 * @Package com.kele.service.impl
 * @Description TODO
 * @Author zhixingbai
 * @Create 2018/9/3010:43
 */
@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    SysUserDao sysUserDao;


    @Override
    public Result login(LoginVo loginInfo) {
        SysUser data=sysUserDao.selectByName(loginInfo.getUsername());
        if(data==null){
           return ResponseFactory.build(CodeMsg.USERNAME_NOT_EXIST);
        }
        String reqPassword=AESOperator.getInstance().encrypt(loginInfo.getPassword());
        if(!data.getPassword().equals(reqPassword)){
            return ResponseFactory.build(CodeMsg.PASSWORD_ERROR);
        }
        return ResponseFactory.build(data);
    }
}
